home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Apps / Apps.sdpd.cgi.z / Apps.sdpd.cgi
Encoding:
Text File  |  1997-07-30  |  11.0 KB  |  371 lines

  1. #!/usr/bin/perl5
  2. #
  3. # Apps.sdpd.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: Apps.sdpd.cgi,v 1.20 1997/06/19 22:26:37 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "ctime.pl";
  24.  
  25. $myname = "Apps.sdpd.cgi";
  26. $add_script = "sdr.cgi";
  27. $announce_dir = "$document_root/apps/sdpd-send";
  28. $received_dir = "$document_root/apps/sdpd-out";
  29.  
  30. $set_cookie = 0;
  31.  
  32. # print "Content-type: text/html\n\n";
  33. # print "here<br>";
  34.  
  35. if ($ARGV[0]) { &create_message; }
  36.  
  37. &get_cookies;
  38.  
  39. &get_files;
  40.  
  41. &get_fields;
  42.  
  43. if (%fld) {
  44.     if ($fld{'get_id'}) { &create_cookie; }
  45.     
  46.     elsif (!$cookie{'sdpd_id'}) { &get_id; }
  47.  
  48.     elsif ($fld{'add'}) { 
  49.         print "Content-type: text/html\n\n";
  50.         print "<HTML><HEAD>";
  51.         print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$add_script\">";
  52.         print "</HEAD><BODY></BODY></HTML>";
  53.         exit 0;
  54.     }
  55.       
  56.     else {    
  57.         $fld{'file'} =~ s/\xa0//g; # get rid of " " characters
  58.         $file = $filename{$fld{'file'}};
  59.  
  60.         if ($fld{'edit'}) { 
  61.             $go = $add_script . "?" . $file;
  62.             print "Content-type: text/html\n\n";
  63.             print "<HTML><HEAD>";
  64.             print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  65.             print "</HEAD><BODY></BODY></HTML>";
  66.             exit 0;
  67.         }
  68.         else {
  69.         unlink $file;
  70.             &get_files;
  71.             $message = "Announcement \"$fld{'file'}\" deleted.";
  72.         }
  73.             
  74.     }
  75. }
  76.  
  77. $javascript = 
  78. "which = \"none\";
  79. function runSubmit() {
  80.     // onClick gets processed before onSubmit
  81.     if(which == \"select\") return runSelect();
  82.     return (true);
  83. }
  84. function markSelect() { which = \"select\"; }
  85. function markOther() { which = \"none\"; }
  86. function runSelect()  {
  87.     Ctrl = document.page1.file; none = true;
  88.     for(i = 0; i < Ctrl.length; i++) { 
  89.         if (Ctrl.options[i].selected) { none = false; break; } 
  90.     }
  91.     if(none) { 
  92.         errorBox (Ctrl, \"You have not selected an announcement\\nfrom the list.\"); return (false); 
  93.     }
  94.     return (true);
  95. }
  96. function errorBox (Ctrl, ErrorMessage) {
  97.     alert (ErrorMessage);  Ctrl.focus();  return;
  98. }";
  99.  
  100. &generic;
  101.  
  102. sub create_message {
  103.     local($mode) = $ARGV[0];
  104.     local($session_name) = $ARGV[1];
  105.  
  106.     $session_name =~ s/__/ /g;
  107.  
  108.     $message = "Announcement \"$session_name\" ";
  109.     if ($mode eq "e") { $message .= "edited."; }
  110.     else { $message .= "created."; }
  111. }
  112.  
  113. sub create_cookie {
  114.     local($time) = time;
  115.  
  116.     $fld{'name'} =~ s/ /#/g;
  117.     $fld{'email'} =~ s/ /#/g;
  118.     $fld{'phone'} =~ s/ /#/g;
  119.  
  120.     $cookie_header = "Content-type: text/html\n"
  121.         . "Set-Cookie: sdpd_id=$time; expires=$date; path=/\n"
  122.         . "Set-Cookie: sdpd_name=$fld{'name'}; expires=$date; path=/\n"
  123.         . "Set-Cookie: sdpd_email=$fld{'email'}; expires=$date; path=/\n"
  124.         . "Set-Cookie: sdpd_phone=$fld{'phone'}; expires=$date; path=/\n\n";
  125.  
  126.     $set_cookie = 1;
  127. }
  128.  
  129. sub get_id {
  130.     undef $name, $email, $phone;
  131.  
  132.     print "Content-type: text/html\n\n";
  133.     print "<html><title>Session Directory Manager: User ID</title>";
  134.  
  135.     print "<body bgcolor=#CCC28F background=\"/images/sdr-bg.gif\"\n";
  136.     print "link=#27002B vlink=#00582A text=#800019>\n";
  137.  
  138.     print "<table width=100%>\n";
  139.     print "<tr><th align=left><h1>Personal Information</h1></th>\n";
  140.     print "<th align=right>\n";
  141.     print "<a href=\"/newsplash.shtml\"><img border=0 height=55 width=57 src=\"/apps/home.gif\"></a>\n";
  142.         print "  ";
  143.         print "<a href=\"/apps/Apps.shtml\"><img border=0 height=55 width=57 src=\"/apps/back.gif\"></a>\n";
  144.     print "</tr></table>\n";
  145.  
  146.     print "<form action=$add_script method=post>\n";
  147.     
  148.     print "<center><table width=400>\n";
  149.     print qq|<tr><th align=left>Name:</th><td>|, 
  150.         &text("sdpd_name","",20),
  151.         qq|</td></tr>\n|;
  152.         print qq|<tr><th align=left>E-mail address:</th><td>|, 
  153.                 &text("sdpd_email","",20),
  154.                 qq|</td></tr>\n|;
  155.         print qq|<tr><th align=left>Telephone number:</th><td>|, 
  156.                 &text("sdpd_phone","",20),
  157.                 qq|</td></tr>\n|;
  158.     print qq|</table><br><br>\n|;
  159.  
  160.     print qq|<input type="submit" name="get_id" value="Submit Information">|;
  161.     
  162.     print qq|</center></form></body></html>|;
  163.  
  164.     exit 0;
  165. }
  166.  
  167. sub get_cookies {
  168.     local($a, $b);
  169.     undef %cookie;
  170.     foreach (split(/; /, $ENV{HTTP_COOKIE})) {
  171.         ($a, $b) = split(/=/, $_);
  172.         $cookie{$a} = $b;
  173. #        $message .= "cookie: $a $b<br>";
  174.     }
  175. }
  176.  
  177. sub get_files {
  178.     local(@filenames);
  179.  
  180.     if (-e $announce_dir)  {
  181.         opendir(DIR, $announce_dir);
  182.         @filenames = readdir(DIR);
  183.         closedir(DIR);
  184.     } else { mkdir($announce_dir, 0755); }
  185.  
  186.     undef @subjects, %filename;
  187.     foreach (@filenames) {
  188.         next if ($_ eq '.' || $_ eq '..');
  189.         $file = $announce_dir . "/" . $_;
  190.         open(IN, $file) || die "Can't open $file";
  191.         $file_id = (split(/\s+/,<IN>))[1];
  192.         if ($file_id eq $cookie{'sdpd_id'}) {
  193.             while(<IN>) {
  194.                 @items = split(/=/);
  195.                 if ($items[0] eq 's') {
  196.                     chop $items[1];
  197.                     push(@subjects,$items[1]);
  198.                     $filename{$items[1]} = $file;
  199.                 }
  200.             }
  201.         }
  202.         close(IN);
  203.     }
  204. }
  205.  
  206. sub make_list {
  207.     local(@filenames);
  208.  
  209.     if (-d $received_dir) {
  210.         opendir(DIR, $received_dir);
  211.                @filenames = readdir(DIR);
  212.                closedir(DIR);
  213.     } else { mkdir($received_dir, 0755); }
  214.  
  215.     print "<b><ol>\n";
  216.     $num = 1;
  217.  
  218.     foreach $file (@filenames) {
  219.                 next if ($file eq '.' || $file eq '..'); 
  220.         $file = $received_dir . "/" . $file;
  221.                 
  222.         open(IN, $file) || die "Can't open $file";
  223.         $radio = 0;
  224.             
  225.         while(<IN>) {
  226.             chop($_);
  227.                 
  228.             if ($_ eq "radio") { $radio = 1; }
  229.             @items = split(/=/,$_);
  230.             
  231.             if ($items[0] eq "s") { $session_name = $items[1]; }
  232.             elsif ($items[0] eq "i") { $session_desc = $items[1]; }
  233.         }
  234.         close(IN);
  235.         
  236.         print "<li><a href=\"#$num\">";
  237.         
  238.         if ($radio) { print $session_desc; }
  239.         else        { print $session_name; }
  240.         
  241.         print "</a>\n";
  242.         $num++;
  243.     }
  244.  
  245.     print "</ol></b><hr>\n";
  246. }
  247.  
  248. sub make_links {
  249.     local(@filenames);
  250.  
  251.     if (-d $received_dir) {
  252.             opendir(DIR, $received_dir);
  253.                @filenames = readdir(DIR);
  254.             closedir(DIR);
  255.     } else { mkdir($received_dir, 0755); }
  256.  
  257.         $num = 1;
  258.         foreach $file (@filenames) {
  259.                 next if ($file eq '.' || $file eq '..');
  260.  
  261.                 $url = $ENV{SERVER_URL} . "/apps/sdpd-out/$file?";
  262.  
  263.                 $file = $received_dir . "/" . $file;
  264.  
  265.         $mnum = 0;
  266.         undef @mvalue;
  267.         $radio = 0;
  268.                 open(IN, $file) || die "Can't open $file";
  269.         while(<IN>) {
  270.             if ($_ eq "radio\n") { $radio = 1; }
  271.             ($a, $b) = split(/=/);
  272.             chop($b);
  273.             if ($a eq "m") { $mvalue[$mnum++] = $b; }
  274.             else { $value{$a} = $b; }
  275.         }
  276.         close(IN);
  277.  
  278.         print "<a name=\"$num\">\n";
  279.  
  280.         print "<table width=100%>\n";
  281.  
  282.         print "<tr><td colspan=3><b>Session:</b> $value{'s'}</td></tr>\n";
  283.         print "<tr><td colspan=3><b>Description:</b> $value{'i'}</td></tr>\n";
  284.         print "<tr><td colspan=3><b>Reference:</b>" 
  285.             . "<a href=\"$value{'u'}\">$value{'u'}</a></td></tr>\n";
  286.  
  287.         if ($value{'t'} && $value{'t'} ne "0 0") {    
  288.             ($ts, $tf) = split(/\s+/, $value{'t'});
  289.             $ts -= 2208988800; $tf -= 2208988800;
  290.             $date_start = &ctime($ts); $date_finish = &ctime($tf);
  291.         } else { $date_start = ""; }
  292.  
  293.         print "<tr><td rowspan=2 width=50%>";
  294.  
  295.         if ($radio) { 
  296.             print "<a href=$url" . "radio>" 
  297.                 ."<img height=40 width=58 src=\"/images/sdr-radio.gif\"></a>\n";
  298.         } else {
  299.             for ($mnum=0; $mnum<=$#mvalue; $mnum++) {
  300.                 $media = (split(/\s+/,$mvalue[$mnum]))[0];
  301.                 $media =~ s/whiteboard/wb/;
  302.                 $src = "/images/sdr-" . $media . ".gif";
  303.                 print "<a href=$url";
  304.                 print "$media><img height=40 width=58 src=$src></a>\n";
  305.                 print "  \n";
  306.             }
  307.         }
  308.                 
  309.         print "</td>";
  310.  
  311.         if ($date_start) {
  312.             print "<td align=left><b>Start:</b></td><td align=left>$date_start</td></tr>\n";
  313.             print "<tr align=left><td><b>Finish:</b></td><td align=left>$date_finish</td>\n";
  314.         }  
  315.         print "</tr></table><hr>\n";
  316.  
  317.         $num++;
  318.         undef %value;
  319.     }
  320. }
  321.     
  322. sub generic {
  323.     print "Content-type: text/html\n\n";
  324.  
  325.     print "<html><head><title>Network Multicast Announcements</title>\n";
  326.     print "<script language=\"JavaScript\">\n";
  327.     print "<!--\n\n$javascript\n\n// -->\n";
  328.     print "</script></head>\n";
  329.     print "<body bgcolor=#CCC28F background=\"/images/sdr-bg.gif\"\n";
  330.     print "link=#27002B vlink=#00582A text=#800019>\n";
  331.  
  332.     print "<table width=100%>\n";
  333.     print "<tr><th align=left><h1>Network Multicast Announcements</h1></th>\n";
  334.     print "<th align=right>\n";
  335.     print "<a href=\"/apps/sdpd_hlp.cgi\"><img border=0 height=65 width=30 src=\"/images/help.gif\"></a>\n";
  336.     print "  ";
  337.     print "<a href=\"/newsplash.shtml\"><img border=0 height=55 width=57 src=\"/apps/home.gif\"></a>\n";
  338.         print "  ";
  339.         print "<a href=\"/apps/Apps.shtml\"><img border=0 height=55 width=57 src=\"/apps/back.gif\"></a>\n";
  340.     print "</tr></table>\n";
  341.  
  342.     print $message, "<br>\n";
  343.  
  344.     print "<form name=page1 method=post action=$myname onSubmit=\"return runSubmit()\">\n";    
  345.  
  346.     print "<table width=600>";
  347.     
  348.     print "<tr><td>"; 
  349.     print qq|<input type=submit name="add" value="Create New Announcement"|,
  350.           qq| onClick="markOther()">|;
  351.     print "</td></tr>";
  352.  
  353.     if ($#subjects > -1) {
  354.  
  355.         print qq|<tr><td><input type=submit name="edit" value="Edit Selected |,
  356.               qq| Announcement" onClick="markSelect()"></td>|;
  357.         print "<td rowspan=2>"; 
  358.         print &choice_list(*subjects, "file", 20), "\n";
  359.         print qq|</td></tr><tr><td><input type=submit name="delete" |,
  360.               qq|value="Delete Selected Announcement" onClick="markSelect()">|;
  361.         print "</td></tr>\n";
  362.     }
  363.     
  364.     print "</table></form><hr>";
  365.     
  366.     &make_list;    
  367.     &make_links;
  368.  
  369.     print "</body></html>\n";
  370. }
  371.